package com.xbongbong.saas.model.impl;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.saas.domain.dao.CustomerInvoiceDao;
import com.xbongbong.saas.domain.entity.CustomerInvoiceEntity;
import com.xbongbong.saas.model.CustomerInvoiceModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author feng.zheng
 * @version v1.0
 * @date 2019/2/27 16:29
 * @since v1.0
 */
@Service("customerInvoiceModel")
public class CustomerInvoiceModelImpl implements CustomerInvoiceModel {

    @Resource
    private CustomerInvoiceDao dao;

    /**
     * 插入
     *
     * @param entity 实体
     * @return 是否成功
     * @throws XbbException 数据库操作异常
     */
    @Override
    public Integer insert(CustomerInvoiceEntity entity) throws XbbException {
        long now = DateTimeUtil.getInt();
        entity.setAddTime(now);
        entity.setUpdateTime(now);
        return dao.insert(entity);
    }

    /**
     * 更新
     *
     * @param entity 实体
     * @return 是否成功
     * @throws XbbException 数据库操作异常
     */
    @Override
    public Integer update(CustomerInvoiceEntity entity) throws XbbException {
        long now = DateTimeUtil.getInt();
        entity.setUpdateTime(now);
        return dao.update(entity);
    }

    /**
     * 根据查询条件查出实体集合
     *
     * @param param 参数
     * @return java.util.List<com.xbongbong.saas.domain.entity.ext.CustomerInvoiceEntity>
     * @author feng.zheng
     * @date 2019/2/25 10:40
     */
    @Override
    public List<CustomerInvoiceEntity> findEntitys(Map<String, Object> param) {
        return dao.findEntitys(param);
    }

    /**
     * 获取符合查询条件的记录总数
     *
     * @param param 查询条件
     * @return 符合查询条件的记录总数
     */
    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return dao.getEntitysCount(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    /**
     * 数据单条查询
     *
     * @param key    主键ID
     * @param corpid 公司ID
     * @return Integer
     * @author feng.zheng
     * @date 2019/1/23 20:27
     * @since v1.0
     */
    @Override
    public CustomerInvoiceEntity getByKey(Long key, String corpid) {
        return dao.getByKey(key, corpid);
    }

    /**
     * 根据id删除
     *
     * @param key    主键
     * @param corpid 公司id
     * @return java.lang.Integer
     * @author feng.zheng
     * @date 2019/2/22 20:23
     */
    @Override
    public Integer deleteByKey(Long key, String corpid) throws XbbException {
        return dao.deleteByKey(key, corpid);
    }
}
